//
//  VRHomeHotCell.swift
//  VoiceRoom
//
//  Created by Rui on 2024/3/16.
//

import UIKit

class VRHomeHotCell: UICollectionViewCell {
    
    private let bgImageView = c_make_ex(UIImageView.self)
        .corner(10).mode(.scaleAspectFill).end()
    private let tagView = c_make_ex(UIButton.self)
        .corner(10).font(11.font_semiBold)
        .color(.white.alpha(0.8))
        .bgColor("#0F0112".toColor.alpha(0.2)).end()
    private let hotView = UIIconButton(style: .leading(itemSpace: 3))
    private let houseLabel = c_make_ex(UILabel.self)
        .font(14.font_semiBold).color(.white).end()
    private let iconImageView = c_make_ex(UIImageView.self)
        .corner(11).mode(.scaleAspectFill).end()
    private let nameLabel = c_make_ex(UILabel.self)
        .font(12.font_medium).color(.white).end()
    private let voiceImageView = c_make_ex(UIImageView.self)
        .image("Home_voice").end()
    
    var model: InfoUtil.room?{
        didSet{
            guard let md = model else { return }
            
            bgImageView.loadImage(url: md.icon)
            if md.info7 == "1"{
                tagView.setTitle("Voice", for: .normal)
                voiceImageView.isHidden = false
            }else{
                if md.info9 == "0" {
                    tagView.setTitle("Male", for: .normal)
                }else{
                    tagView.setTitle("Female", for: .normal)
                }
                voiceImageView.isHidden = true
            }
            houseLabel.text = md.houseName
            iconImageView.loadImage(url: md.info1)
            nameLabel.text = md.info2
        }
    }

    override init(frame: CGRect) {
        super.init(frame: frame)
        contentView.subviews {
            bgImageView
            tagView
            hotView
            houseLabel
            iconImageView
            nameLabel
            voiceImageView
        }
        
        bgImageView.fillContainer()
        tagView.trailing(10).top(10).height(20).width(45)
        hotView.leading(10).top(10).height(20)
        houseLabel.leading(10).trailing(10)
        iconImageView.leading(10).bottom(10).size(22)
        houseLabel.Bottom == iconImageView.Top - 5
        nameLabel.leading(40)
        nameLabel.CenterY == iconImageView.CenterY
        voiceImageView.trailing(10).bottom(10).size(18)
        
        tagView.isUserInteractionEnabled = false
//        tagView.contentEdgeInsets = UIEdgeInsets(top: 0, left: 10, bottom: 0, right: 10)
        hotView.style { v in
            v.setImage("Home_hot".toImage, for: .normal)
            v.iconSize = CGSize(width: 15, height: 15)
            v.titleLabel?.font = 11.font_semiBold
            v.setTitleColor(.white.alpha(0.8), for: .normal)
            v.contentEdgeInsets = UIEdgeInsets(top: 0, left: 10, bottom: 0, right: 10)
            v.isUserInteractionEnabled = false
        }
        
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
}

class VRHomeDisCell: UICollectionViewCell {
    
    private let imageView = c_make_ex(UIImageView.self)
        .corner(10).mode(.scaleAspectFill).end()
    
    var model: InfoUtil.room?{
        didSet{
            guard let md = model else { return }
            imageView.loadImage(url: md.icon)
        }
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        contentView.subviews {
            imageView
        }
        
        imageView.fillContainer()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}

class VRHomeMultiCell: UICollectionViewCell {
    
    private let imageView = c_make_ex(UIImageView.self)
        .corner(10).mode(.scaleAspectFill).end()
    private let houseLabel = c_make_ex(UILabel.self)
        .font(14.font_semiBold).color(.white).end()
    private let peopleLabel = UIIconButton(style: .leading(itemSpace: 3))
    private let oneIconImage = c_make_ex(UIImageView.self)
        .corner(16).mode(.scaleAspectFill).end()
    private let twoIconImage = c_make_ex(UIImageView.self)
        .corner(16).mode(.scaleAspectFill).end()
    private let threeIconImage = c_make_ex(UIImageView.self)
        .corner(16).mode(.scaleAspectFill).end()
    
    var model: InfoUtil.room?{
        didSet{
            guard let md = model else { return }
            
            imageView.loadImage(url: md.icon)
            houseLabel.text = md.houseName
        }
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        contentView.subviews {
            imageView.subviews{
                peopleLabel
                oneIconImage
                twoIconImage
                threeIconImage
            }
            houseLabel
        }
        
        imageView.leading(0).trailing(0).top(0).height((CGFloat.screenWidth - 25.0)/2)
        houseLabel.leading(10)
        houseLabel.Top == imageView.Bottom + 10
        peopleLabel.trailing(10).top(10).height(20)
        oneIconImage.leading(10).bottom(10).size(32)
        twoIconImage.size(32)
        twoIconImage.CenterY == oneIconImage.CenterY
        twoIconImage.Leading == oneIconImage.Trailing - 4
        threeIconImage.size(32)
        threeIconImage.CenterY == twoIconImage.CenterY
        threeIconImage.Leading == twoIconImage.Trailing - 4
        
        peopleLabel.style { v in
            v.backgroundColor = "#0F0112".toColor.alpha(0.2)
            v.setImage("Home_people".toImage, for: .normal)
            v.iconSize = CGSize(width: 15, height: 15)
            v.setTitleColor(.white, for: .normal)
            v.titleLabel?.font = 11.font_semiBold
            v.contentEdgeInsets = UIEdgeInsets(top: 0, left: 7, bottom: 0, right: 7)
            v.layer.cornerRadius = 10
            v.layer.masksToBounds = true
            v.isUserInteractionEnabled = false
        }
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}

